{
 "metadata": {
  "name": "",
  "signature": "sha256:d22fcd7d5554395cbf13d39241e667b0847c45204dbdcffcc0abb5cfe265e4b8"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from shapely.geometry import Polygon, Point\n",
      "\n",
      "from rockfish2.navigation.p190 import P190"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p190 = P190(database='/Users/ncm/Dev/Rockfish2/rockfish2/navigation/p190/tests/temp.sqlite')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stderr",
       "text": [
        "[2014-10-17 13:11] INFO: rockfish: Connecting to existing database: /Users/ncm/Dev/Rockfish2/rockfish2/navigation/p190/tests/temp.sqlite\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "bins = p190.read_sql('SELECT * FROM cmp_line')\n",
      "nbins = len(bins)\n",
      "\n",
      "bins[0:5]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>bin</th>\n",
        "      <th>easting</th>\n",
        "      <th>northing</th>\n",
        "      <th>distance</th>\n",
        "      <th>x1</th>\n",
        "      <th>y1</th>\n",
        "      <th>x2</th>\n",
        "      <th>y2</th>\n",
        "      <th>x3</th>\n",
        "      <th>y3</th>\n",
        "      <th>x4</th>\n",
        "      <th>y4</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td> 1000</td>\n",
        "      <td> 65654.350000</td>\n",
        "      <td> 3598677.200000</td>\n",
        "      <td>  0.00</td>\n",
        "      <td> 65676.533210</td>\n",
        "      <td> 3598722.118491</td>\n",
        "      <td> 65681.953542</td>\n",
        "      <td> 3598719.006819</td>\n",
        "      <td> 65632.166790</td>\n",
        "      <td> 3598632.281509</td>\n",
        "      <td> 65626.746458</td>\n",
        "      <td> 3598635.393181</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td> 1001</td>\n",
        "      <td> 65651.238328</td>\n",
        "      <td> 3598682.620332</td>\n",
        "      <td>  6.25</td>\n",
        "      <td> 65673.421538</td>\n",
        "      <td> 3598727.538823</td>\n",
        "      <td> 65678.841870</td>\n",
        "      <td> 3598724.427151</td>\n",
        "      <td> 65629.055118</td>\n",
        "      <td> 3598637.701841</td>\n",
        "      <td> 65623.634786</td>\n",
        "      <td> 3598640.813513</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td> 1002</td>\n",
        "      <td> 65648.126656</td>\n",
        "      <td> 3598688.040664</td>\n",
        "      <td> 12.50</td>\n",
        "      <td> 65670.309866</td>\n",
        "      <td> 3598732.959155</td>\n",
        "      <td> 65675.730198</td>\n",
        "      <td> 3598729.847483</td>\n",
        "      <td> 65625.943446</td>\n",
        "      <td> 3598643.122173</td>\n",
        "      <td> 65620.523114</td>\n",
        "      <td> 3598646.233845</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td> 1003</td>\n",
        "      <td> 65645.014984</td>\n",
        "      <td> 3598693.460996</td>\n",
        "      <td> 18.75</td>\n",
        "      <td> 65667.198194</td>\n",
        "      <td> 3598738.379486</td>\n",
        "      <td> 65672.618526</td>\n",
        "      <td> 3598735.267814</td>\n",
        "      <td> 65622.831774</td>\n",
        "      <td> 3598648.542505</td>\n",
        "      <td> 65617.411442</td>\n",
        "      <td> 3598651.654177</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td> 1004</td>\n",
        "      <td> 65641.903312</td>\n",
        "      <td> 3598698.881327</td>\n",
        "      <td> 25.00</td>\n",
        "      <td> 65664.086522</td>\n",
        "      <td> 3598743.799818</td>\n",
        "      <td> 65669.506854</td>\n",
        "      <td> 3598740.688146</td>\n",
        "      <td> 65619.720102</td>\n",
        "      <td> 3598653.962837</td>\n",
        "      <td> 65614.299770</td>\n",
        "      <td> 3598657.074509</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "    bin       easting        northing  distance            x1              y1  \\\n",
        "0  1000  65654.350000  3598677.200000      0.00  65676.533210  3598722.118491   \n",
        "1  1001  65651.238328  3598682.620332      6.25  65673.421538  3598727.538823   \n",
        "2  1002  65648.126656  3598688.040664     12.50  65670.309866  3598732.959155   \n",
        "3  1003  65645.014984  3598693.460996     18.75  65667.198194  3598738.379486   \n",
        "4  1004  65641.903312  3598698.881327     25.00  65664.086522  3598743.799818   \n",
        "\n",
        "             x2              y2            x3              y3            x4  \\\n",
        "0  65681.953542  3598719.006819  65632.166790  3598632.281509  65626.746458   \n",
        "1  65678.841870  3598724.427151  65629.055118  3598637.701841  65623.634786   \n",
        "2  65675.730198  3598729.847483  65625.943446  3598643.122173  65620.523114   \n",
        "3  65672.618526  3598735.267814  65622.831774  3598648.542505  65617.411442   \n",
        "4  65669.506854  3598740.688146  65619.720102  3598653.962837  65614.299770   \n",
        "\n",
        "               y4  \n",
        "0  3598635.393181  \n",
        "1  3598640.813513  \n",
        "2  3598646.233845  \n",
        "3  3598651.654177  \n",
        "4  3598657.074509  "
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "poly = [Polygon(([bins.loc[i, 'x1'], bins.loc[i, 'y1']],\n",
      "            [bins.loc[i, 'x2'], bins.loc[i, 'y2']],\n",
      "            [bins.loc[i, 'x3'], bins.loc[i, 'y3']],\n",
      "            [bins.loc[i, 'x4'], bins.loc[i, 'y4']]))\\\n",
      "                    for i in range(nbins)]\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "rec = p190.read_sql('SELECT * FROM receiver_groups WHERE point_number=91015')\n",
      "\n",
      "rec[0:5]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>line_name</th>\n",
        "      <th>point_number</th>\n",
        "      <th>receiver_group</th>\n",
        "      <th>easting</th>\n",
        "      <th>northing</th>\n",
        "      <th>cable_depth</th>\n",
        "      <th>streamer_id</th>\n",
        "      <th>offset</th>\n",
        "      <th>midpoint_easting</th>\n",
        "      <th>midpoint_northing</th>\n",
        "      <th>cmp_model</th>\n",
        "      <th>cmp_bin</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td> MGL1407MCS15</td>\n",
        "      <td> 91015</td>\n",
        "      <td> 468</td>\n",
        "      <td> 63568.9</td>\n",
        "      <td> 3600379.1</td>\n",
        "      <td> 9.1</td>\n",
        "      <td> 1</td>\n",
        "      <td> 158.825974</td>\n",
        "      <td> 63528.30</td>\n",
        "      <td> 3600447.35</td>\n",
        "      <td> None</td>\n",
        "      <td> None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td> MGL1407MCS15</td>\n",
        "      <td> 91015</td>\n",
        "      <td> 467</td>\n",
        "      <td> 63579.7</td>\n",
        "      <td> 3600372.8</td>\n",
        "      <td> 9.0</td>\n",
        "      <td> 1</td>\n",
        "      <td> 169.870068</td>\n",
        "      <td> 63533.70</td>\n",
        "      <td> 3600444.20</td>\n",
        "      <td> None</td>\n",
        "      <td> None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td> MGL1407MCS15</td>\n",
        "      <td> 91015</td>\n",
        "      <td> 466</td>\n",
        "      <td> 63590.6</td>\n",
        "      <td> 3600366.6</td>\n",
        "      <td> 9.0</td>\n",
        "      <td> 1</td>\n",
        "      <td> 181.078464</td>\n",
        "      <td> 63539.15</td>\n",
        "      <td> 3600441.10</td>\n",
        "      <td> None</td>\n",
        "      <td> None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td> MGL1407MCS15</td>\n",
        "      <td> 91015</td>\n",
        "      <td> 465</td>\n",
        "      <td> 63601.4</td>\n",
        "      <td> 3600360.3</td>\n",
        "      <td> 9.0</td>\n",
        "      <td> 1</td>\n",
        "      <td> 192.472803</td>\n",
        "      <td> 63544.55</td>\n",
        "      <td> 3600437.95</td>\n",
        "      <td> None</td>\n",
        "      <td> None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td> MGL1407MCS15</td>\n",
        "      <td> 91015</td>\n",
        "      <td> 464</td>\n",
        "      <td> 63612.1</td>\n",
        "      <td> 3600353.9</td>\n",
        "      <td> 9.0</td>\n",
        "      <td> 1</td>\n",
        "      <td> 204.015318</td>\n",
        "      <td> 63549.90</td>\n",
        "      <td> 3600434.75</td>\n",
        "      <td> None</td>\n",
        "      <td> None</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "      line_name  point_number  receiver_group  easting   northing  \\\n",
        "0  MGL1407MCS15         91015             468  63568.9  3600379.1   \n",
        "1  MGL1407MCS15         91015             467  63579.7  3600372.8   \n",
        "2  MGL1407MCS15         91015             466  63590.6  3600366.6   \n",
        "3  MGL1407MCS15         91015             465  63601.4  3600360.3   \n",
        "4  MGL1407MCS15         91015             464  63612.1  3600353.9   \n",
        "\n",
        "   cable_depth  streamer_id      offset  midpoint_easting  midpoint_northing  \\\n",
        "0          9.1            1  158.825974          63528.30         3600447.35   \n",
        "1          9.0            1  169.870068          63533.70         3600444.20   \n",
        "2          9.0            1  181.078464          63539.15         3600441.10   \n",
        "3          9.0            1  192.472803          63544.55         3600437.95   \n",
        "4          9.0            1  204.015318          63549.90         3600434.75   \n",
        "\n",
        "  cmp_model cmp_bin  \n",
        "0      None    None  \n",
        "1      None    None  \n",
        "2      None    None  \n",
        "3      None    None  \n",
        "4      None    None  "
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Search all polygons"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pts = [Point(rec.ix[i]['midpoint_easting'], rec.ix[i]['midpoint_northing']) for i in range(len(rec))]\n",
      "\n",
      "pt_in_bin = [np.nonzero([p.contains(pt) for p in poly])[0] for pt in pts]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 26
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pt_in_bin"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 27,
       "text": [
        "[array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([79]),\n",
        " array([78]),\n",
        " array([77]),\n",
        " array([76]),\n",
        " array([75]),\n",
        " array([74]),\n",
        " array([73]),\n",
        " array([72]),\n",
        " array([71]),\n",
        " array([69, 70]),\n",
        " array([69]),\n",
        " array([68]),\n",
        " array([66]),\n",
        " array([65]),\n",
        " array([64]),\n",
        " array([63]),\n",
        " array([62]),\n",
        " array([61]),\n",
        " array([60]),\n",
        " array([59]),\n",
        " array([58]),\n",
        " array([57]),\n",
        " array([56]),\n",
        " array([55]),\n",
        " array([53]),\n",
        " array([52]),\n",
        " array([51]),\n",
        " array([50]),\n",
        " array([49]),\n",
        " array([48]),\n",
        " array([47]),\n",
        " array([46]),\n",
        " array([45]),\n",
        " array([44]),\n",
        " array([43]),\n",
        " array([42]),\n",
        " array([40]),\n",
        " array([39]),\n",
        " array([38]),\n",
        " array([37]),\n",
        " array([36]),\n",
        " array([35]),\n",
        " array([34]),\n",
        " array([33]),\n",
        " array([32]),\n",
        " array([31]),\n",
        " array([30, 31]),\n",
        " array([29, 30]),\n",
        " array([27, 28]),\n",
        " array([26]),\n",
        " array([25]),\n",
        " array([24]),\n",
        " array([23]),\n",
        " array([22]),\n",
        " array([21]),\n",
        " array([20]),\n",
        " array([19]),\n",
        " array([18]),\n",
        " array([17, 18]),\n",
        " array([16, 17]),\n",
        " array([15]),\n",
        " array([13, 14]),\n",
        " array([12, 13]),\n",
        " array([11]),\n",
        " array([10]),\n",
        " array([9]),\n",
        " array([8]),\n",
        " array([7]),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([5]),\n",
        " array([3, 4]),\n",
        " array([2, 3]),\n",
        " array([1]),\n",
        " array([0]),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64),\n",
        " array([], dtype=int64)]"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Search within range of last assignement"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def find_polys(pts, poly, nsearch_max=200):\n",
      "     \n",
      "    npoly = len(poly)\n",
      "    search_range = [0, npoly]\n",
      "    inbins = -999 * np.ones(len(pts))\n",
      "    for ipt, pt in enumerate(pts):\n",
      "        ip = range(*search_range)\n",
      "        _inbins = np.nonzero([poly[i].contains(pt) for i in ip])[0]\n",
      "        if len(_inbins) > 0:\n",
      "            inbins[ipt] = _inbins[0]\n",
      "            ip0 = _inbins[0]\n",
      "            search_range = [max(0, ip0 - nsearch_max), min(npoly, ip0 + nsearch_max)]\n",
      "            \n",
      "    return inbins"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 40
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pt_in_bin = find_polys(pts, poly)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 41
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "[(i, pt_in_bin[i]) for i in range(len(pt_in_bin)) if pt_in_bin[i] > 0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 46,
       "text": [
        "[(227, 79.0),\n",
        " (228, 78.0),\n",
        " (229, 77.0),\n",
        " (230, 76.0),\n",
        " (231, 75.0),\n",
        " (232, 74.0),\n",
        " (233, 73.0),\n",
        " (234, 72.0),\n",
        " (235, 71.0),\n",
        " (236, 69.0),\n",
        " (237, 69.0),\n",
        " (238, 68.0),\n",
        " (239, 66.0),\n",
        " (240, 65.0),\n",
        " (241, 64.0),\n",
        " (242, 63.0),\n",
        " (243, 62.0),\n",
        " (244, 61.0),\n",
        " (245, 60.0),\n",
        " (246, 59.0),\n",
        " (247, 58.0),\n",
        " (248, 57.0),\n",
        " (249, 56.0),\n",
        " (250, 55.0),\n",
        " (251, 53.0),\n",
        " (252, 52.0),\n",
        " (253, 51.0),\n",
        " (254, 50.0),\n",
        " (255, 49.0),\n",
        " (256, 48.0),\n",
        " (257, 47.0),\n",
        " (258, 46.0),\n",
        " (259, 45.0),\n",
        " (260, 44.0),\n",
        " (261, 43.0),\n",
        " (262, 42.0),\n",
        " (263, 40.0),\n",
        " (264, 39.0),\n",
        " (265, 38.0),\n",
        " (266, 37.0),\n",
        " (267, 36.0),\n",
        " (268, 35.0),\n",
        " (269, 34.0),\n",
        " (270, 33.0),\n",
        " (271, 32.0),\n",
        " (272, 31.0),\n",
        " (273, 30.0),\n",
        " (274, 29.0),\n",
        " (275, 27.0),\n",
        " (276, 26.0),\n",
        " (277, 25.0),\n",
        " (278, 24.0),\n",
        " (279, 23.0),\n",
        " (280, 22.0),\n",
        " (281, 21.0),\n",
        " (282, 20.0),\n",
        " (283, 19.0),\n",
        " (284, 18.0),\n",
        " (285, 17.0),\n",
        " (286, 16.0),\n",
        " (287, 15.0),\n",
        " (288, 13.0),\n",
        " (289, 12.0),\n",
        " (290, 11.0),\n",
        " (291, 10.0),\n",
        " (292, 9.0),\n",
        " (293, 8.0),\n",
        " (294, 7.0),\n",
        " (299, 5.0),\n",
        " (300, 3.0),\n",
        " (301, 2.0),\n",
        " (302, 1.0)]"
       ]
      }
     ],
     "prompt_number": 46
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}